package com.lucky.auth_boot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lucky.auth_boot.mapper.DomainMapper;
import com.lucky.auth_boot.mapper.PirateMapper;
import com.lucky.auth_boot.mapper.SystemConfigMapper;
import com.lucky.auth_boot.mapper.UserMapper;
import com.lucky.auth_boot.pojo.po.SystemConfigPO;
import com.lucky.auth_boot.pojo.vo.SiteInfoVO;
import com.lucky.auth_boot.service.SiteInfoService;
import jakarta.annotation.Resource;
import org.apache.catalina.util.ServerInfo;
import org.springframework.stereotype.Service;

@Service
public class SiteInfoServiceImpl implements SiteInfoService {
    @Resource
    private SystemConfigMapper systemConfigMapper;
    @Resource
    private PirateMapper pirateMapper;
    @Resource
    private DomainMapper domainMapper;
    @Resource
    private UserMapper userMapper;

    @Override
    public SiteInfoVO querySiteInfo() {
        SiteInfoVO siteInfoVO = new SiteInfoVO();
        try {
            siteInfoVO.setStatus(1);

            QueryWrapper<SystemConfigPO> wrapper = new QueryWrapper<>();
            wrapper.orderByAsc("id").last("LIMIT 1");
            SystemConfigPO systemConfigPO = systemConfigMapper.selectOne(wrapper);
            siteInfoVO.setSiteName(systemConfigPO.getWebName());
            siteInfoVO.setSystemVersion(systemConfigPO.getSystemVersion());

            siteInfoVO.setPirateSiteNum(Math.toIntExact(pirateMapper.selectCount(null)));
            siteInfoVO.setAuthSiteNum(Math.toIntExact(domainMapper.selectCount(null)));
            siteInfoVO.setUserNum(String.valueOf(userMapper.selectCount(null)));

            return siteInfoVO;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
